package com.net.wanjian.networkhospitalmanager.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.activity.base.BaseActivity;
import com.net.wanjian.networkhospitalmanager.consts.SharedPreferencesKeyConst;
import com.net.wanjian.networkhospitalmanager.net.HttpUtil;
import com.net.wanjian.networkhospitalmanager.netstatus.NetUtils;
import com.net.wanjian.networkhospitalmanager.utils.DensityToPxUtil;
import com.net.wanjian.networkhospitalmanager.utils.PicassoUtil;
import com.net.wanjian.networkhospitalmanager.utils.QRCodeUtil;
import com.net.wanjian.networkhospitalmanager.utils.SharedXmlUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyQRcodeActivity extends BaseActivity {

    @BindView(R.id.top_back_layout)
    LinearLayout topBackLayout;
    @BindView(R.id.top_title_tv)
    TextView topTitleTv;
    @BindView(R.id.dialog_qrcode_header_iv)
    ImageView dialogQrcodeHeaderIv;
    @BindView(R.id.dialog_qrcode_name_tv)
    TextView dialogQrcodeNameTv;
    @BindView(R.id.dialog_qrcode_number_tv)
    TextView dialogQrcodeNumberTv;
    @BindView(R.id.dialog_qrcode_iv)
    ImageView dialogQrcodeIv;
    @BindView(R.id.top_back_text_tv)
    TextView topBackTextTv;

    @Override
    protected void initData() {
        String key = "WANJIAN^USER^"+ SharedXmlUtil.getInstance().read(SharedPreferencesKeyConst.EncryptUser_Identity_ID_key, "");
        topBackTextTv.setText("我");
        topTitleTv.setText("二维码");
        topBackLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyQRcodeActivity.this.finish();
            }
        });

        Bundle bundle = getIntent().getExtras();
        if (null != bundle){
            String trueName = bundle.getString("trueName");
            String num = bundle.getString("number");

            dialogQrcodeNumberTv.setText(num);
            dialogQrcodeNameTv.setText(trueName);

            PicassoUtil.loadImage(this,
                    HttpUtil.getImageUrl(SharedXmlUtil.getInstance().getHospitalId(),
                    SharedXmlUtil.getInstance().getUserInfoId(), 2),
                    R.mipmap.infigure_png,
                    dialogQrcodeHeaderIv);

            Bitmap decodeResource = BitmapFactory.decodeResource(getResources(), R.mipmap.infigure_png);
            Bitmap qrBitmap = QRCodeUtil.createQRImage(key, DensityToPxUtil.dp2px(this, 190), DensityToPxUtil.dp2px(this, 190), decodeResource);
            dialogQrcodeIv.setImageBitmap(qrBitmap);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_qrcode;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

}
